package fr.emse.tatiana.replayable.analysis.graph;

import java.util.Hashtable;
import java.util.Map;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import fr.emse.tatiana.replayable.Anchor;
import fr.emse.tatiana.replayable.analysis.GraphAnalysis;
import fr.emse.tatiana.replayable.analysis.IGraphAnalysis;
import fr.emse.tatiana.replayable.analysis.Link;

public class GraphAnalysisPartFactory implements EditPartFactory {

	private Map<Object,EditPart> objectmap;
	
	public GraphAnalysisPartFactory() {
		super();
		objectmap = new Hashtable<Object, EditPart>();
	}

	public EditPart createEditPart(EditPart context, Object model) {
		AbstractGraphicalEditPart part = null; 
        
        if (model instanceof IGraphAnalysis) {
        	part = new GraphAnalysisPart((GraphAnalysis) model);
        } else if (model instanceof Anchor) {
        	part = new EventGraphPart((Anchor) model);
        } else if (model instanceof Link) {
        	part = new ConnectionEditPart();
        	part.setModel(model);
        }
     
        part.setParent(context);
        objectmap.put(model,part);
        
        return part;
	}
	
	public EditPart getEditPart(Object model) {
		return objectmap.get(model);
	}

}
